package day14.Ti.ZhuSe;

import java.util.concurrent.ArrayBlockingQueue;

public class Ti01 {
    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<String> list = new ArrayBlockingQueue<>(1);
        Foodie f=new Foodie(list);
        Cooker c=new Cooker(list);
        f.start();
        Thread.sleep(1000);
        c.start();
    }
}

class Foodie extends Thread {
    private ArrayBlockingQueue<String>bd;
    public Foodie(ArrayBlockingQueue<String> list) {
        this.bd=list;
    }

    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            try {
                String take = bd.take();
                System.out.println("吃货把"+take+"拿出来吃了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}


class Cooker extends Thread {
    private ArrayBlockingQueue<String>bd;

    public Cooker(ArrayBlockingQueue<String> list) {
        this.bd=list;
    }

    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            try {
                bd.put("第"+i+"汉堡包");
                System.out.println("厨师放入了"+i+"个汉堡包");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
